package framework.command;

import framework.account.IAccount;
import framework.account.IEntry;
import framework.account.Transaction;

public class CreditCommand implements ICommand {
    private IAccount acc;
    private float amount;
    private final String type = "credit";

    public CreditCommand(IAccount acc, float amount) {
        this.acc = acc;
        this.amount = amount;
    }

    public void execute() {
        if (acc.processTransaction(amount)) {
            IEntry tr = new Transaction(type, amount, IEntry.STATUS.SUCCESSFUL);
            acc.addTransaction(tr);
        } else {
            IEntry tr = new Transaction(type, amount, IEntry.STATUS.FAILED);
            acc.addTransaction(tr);
        }
    }

    @Override
    public void execute(IFunctor functor) {
        throw new UnsupportedOperationException();
    }

}
